home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume18 / elm2.2 / part20 < prev    next >
Encoding:
Internet Message Format  |  1989-04-12  |  49.3 KB

  1. Subject:  v18i099:  Elm mail system, release 2.2, Part20/22
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: dsinc!syd@uunet.UU.NET (Syd Weinstein)
  7. Posting-number: Volume 18, Issue 99
  8. Archive-name: elm2.2/part20
  9.  
  10. # this is part 20 of a multipart archive
  11. # do not concatenate these parts, unpack them in order with /bin/sh
  12. # file src/save_opts.c continued
  13. #
  14. CurArch=20
  15. if test ! -r s2_seq_.tmp
  16. then echo "Please unpack part 1 first!"
  17.      exit 1; fi
  18. ( read Scheck
  19.   if test "$Scheck" != $CurArch
  20.   then echo "Please unpack part $Scheck next!"
  21.        exit 1;
  22.   else exit 0; fi
  23. ) < s2_seq_.tmp || exit 1
  24. echo "x - Continuing file src/save_opts.c"
  25. sed 's/^X//' << 'SHAR_EOF' >> src/save_opts.c
  26. X * Bug reports, patches, comments, suggestions should be sent to:
  27. X *
  28. X *    Syd Weinstein, Elm Coordinator
  29. X *    elm@dsinc.UUCP            dsinc!elm
  30. X *
  31. X *******************************************************************************
  32. X * $Log:    save_opts.c,v $
  33. X * Revision 2.17  89/03/25  21:47:09  syd
  34. X * Initial 2.2 Release checkin
  35. X * 
  36. X *
  37. X ******************************************************************************/
  38. X
  39. X/** This file contains the routine needed to allow the users to change the
  40. X    Elm parameters and then save the configuration in a ".elm/elmrc" file in
  41. X    their home directory.  With any luck this will allow them never to have
  42. X    to actually EDIT the file!!
  43. X
  44. X**/
  45. X
  46. X#include "headers.h"
  47. X#include <errno.h>
  48. X
  49. X#undef onoff
  50. X#define   onoff(n)    (n == 1? "ON":"OFF")
  51. X
  52. X#define absolute(x)        ((x) < 0? -(x) : (x))
  53. X
  54. Xextern  int errno;
  55. Xextern char version_buff[];
  56. X
  57. Xchar *error_name(), *sort_name();
  58. Xlong  ftell();
  59. X
  60. X#include "save_opts.h"
  61. X
  62. XFILE *elminfo;        /* informational file as needed... */
  63. X
  64. Xsave_options()
  65. X{
  66. X    /** Save the options currently specified to a file.  This is a
  67. X        fairly complex routine since it tries to put in meaningful
  68. X        comments and such as it goes along.  The comments are
  69. X        extracted from the file ELMRC_INFO as defined in the sysdefs.h
  70. X        file.  THAT file has the format;
  71. X
  72. X        varname
  73. X          <comment>
  74. X          <comment>
  75. X        <blank line>
  76. X
  77. X        and each comment is written ABOVE the variable to be added.  This
  78. X        program also tries to make 'pretty' stuff like the alternatives
  79. X        and such.
  80. X    **/
  81. X
  82. X    FILE *newelmrc; 
  83. X    char  oldfname[SLEN], newfname[SLEN];
  84. X
  85. X    sprintf(newfname, "%s/%s", home, elmrcfile);
  86. X    sprintf(oldfname, "%s/%s", home, old_elmrcfile);
  87. X
  88. X    /** first off, let's see if they already HAVE a .elm/elmrc file **/
  89. X
  90. X    save_file_stats(newfname);
  91. X    if (access(newfname, ACCESS_EXISTS) != -1) {
  92. X      /** YES!  Copy it to the file ".old.elmrc".. **/
  93. X      if (rename(newfname, oldfname) < 0)
  94. X        dprint(2, (debugfile, "Unable to rename %s to %s\n", 
  95. X           newfname, oldfname));
  96. X      (void) chown(oldfname, userid, groupid);
  97. X
  98. X    }
  99. X
  100. X    /** now let's open the datafile if we can... **/
  101. X
  102. X    if ((elminfo = fopen(ELMRC_INFO, "r")) == NULL) 
  103. X      error1("Warning: saving without comments! Can't get to %s.", 
  104. X          ELMRC_INFO);
  105. X
  106. X    /** next, open the new .elm/elmrc file... **/
  107. X
  108. X    if ((newelmrc = fopen(newfname, "w")) == NULL) {
  109. X       error2("Can't save configuration! Can't write to %s [%s].",
  110. X           newfname, error_name(errno));
  111. X       return;
  112. X    }
  113. X    
  114. X    save_user_options(elminfo, newelmrc);
  115. X    restore_file_stats(newfname);
  116. X
  117. X    error1("Options saved in file %s.", newfname);
  118. X}
  119. X
  120. Xsave_user_options(elminfo_fd, newelmrc)
  121. XFILE *elminfo_fd, *newelmrc;
  122. X{
  123. X    /** save the information in the file.  If elminfo_fd == NULL don't look
  124. X        for comments!
  125. X    **/
  126. X
  127. X    if (elminfo_fd != NULL) 
  128. X      build_offset_table(elminfo_fd);
  129. X
  130. X    fprintf(newelmrc,     
  131. X          "#\n# .elm/elmrc - options file for the ELM mail system\n#\n");
  132. X
  133. X    if (strlen(full_username) > 0)
  134. X      fprintf(newelmrc, "# Saved automatically by ELM %s for %s\n#\n\n",
  135. X          version_buff, full_username);
  136. X    else
  137. X      fprintf(newelmrc, "# Saved automatically by ELM %s\n#\n\n", version_buff);
  138. X    fprintf(newelmrc,"# For yes/no settings with ?, ON means yes, OFF means no\n\n");
  139. X
  140. X    save_option_string(CALENDAR, raw_calendar_file, newelmrc, FALSE);
  141. X    save_option_string(EDITOR, raw_editor, newelmrc, FALSE);
  142. X
  143. X    save_option_char(ESCAPECHAR, escape_char, newelmrc);
  144. X
  145. X    save_option_string(FULLNAME, full_username, newelmrc, FALSE);
  146. X    save_option_string(RECEIVEDMAIL, raw_recvdmail, newelmrc, FALSE);
  147. X    save_option_string(MAILDIR, raw_folders, newelmrc, FALSE);
  148. X    save_option_string(PAGER, raw_pager, newelmrc, FALSE);
  149. X    save_option_string(PREFIX, prefixchars, newelmrc, TRUE);
  150. X    save_option_string(PRINT, raw_printout, newelmrc, FALSE);
  151. X    save_option_string(SENTMAIL, raw_sentmail, newelmrc, FALSE);
  152. X    save_option_string(SHELL, raw_shell, newelmrc, FALSE);
  153. X
  154. X    save_option_string(LOCALSIGNATURE, raw_local_signature,
  155. X       newelmrc, FALSE);
  156. X    save_option_string(REMOTESIGNATURE, raw_remote_signature,
  157. X      newelmrc, FALSE);
  158. X
  159. X    save_option_sort(SORTBY, newelmrc);
  160. X
  161. X    save_option_on_off(ALWAYSDELETE, always_del, newelmrc);
  162. X    save_option_on_off(ALWAYSSTORE, always_store, newelmrc);
  163. X    save_option_on_off(ALWAYSKEEP, always_keep, newelmrc);
  164. X    save_option_on_off(ARROW, arrow_cursor, newelmrc);
  165. X    save_option_on_off(ASK, question_me, newelmrc);
  166. X    save_option_on_off(ASKCC, prompt_for_cc, newelmrc);
  167. X    save_option_on_off(AUTOCOPY, auto_copy, newelmrc);
  168. X
  169. X    save_option_number(BOUNCEBACK, bounceback, newelmrc);
  170. X
  171. X    save_option_on_off(COPY, auto_cc, newelmrc);
  172. X    save_option_on_off(FORMS, (allow_forms != NO), newelmrc);
  173. X    save_option_on_off(KEEPEMPTY, keep_empty_files, newelmrc);
  174. X    save_option_on_off(KEYPAD, hp_terminal, newelmrc);
  175. X    save_option_on_off(MENU, mini_menu, newelmrc);
  176. X    save_option_on_off(MOVEPAGE, move_when_paged, newelmrc);
  177. X    save_option_on_off(NAMES, names_only, newelmrc);
  178. X    save_option_on_off(NOHEADER, noheader, newelmrc);
  179. X    save_option_on_off(POINTNEW, point_to_new, newelmrc);
  180. X    save_option_on_off(PROMPTAFTER, prompt_after_pager, newelmrc);
  181. X    save_option_on_off(RESOLVE, resolve_mode, newelmrc);
  182. X    save_option_on_off(SAVENAME, save_by_name, newelmrc);
  183. X    save_option_on_off(SOFTKEYS, hp_softkeys, newelmrc);
  184. X
  185. X    save_option_number(TIMEOUT, (int) timeout, newelmrc);
  186. X
  187. X    save_option_on_off(TITLES, title_messages, newelmrc);
  188. X
  189. X    save_option_number(USERLEVEL, user_level, newelmrc);
  190. X
  191. X    save_option_on_off(WARNINGS, warnings, newelmrc);
  192. X    save_option_on_off(WEED, filter, newelmrc);
  193. X
  194. X    save_option_weedlist(WEEDOUT, newelmrc);
  195. X    save_option_alternatives(ALTERNATIVES, alternative_addresses, newelmrc);
  196. X
  197. X    fclose(newelmrc);
  198. X    if ( elminfo_fd != NULL ) {
  199. X        fclose(elminfo_fd);
  200. X    }
  201. X}
  202. X
  203. Xsave_option_string(iindex, value, fd, underscores)
  204. Xint iindex, underscores;
  205. Xchar *value;
  206. XFILE *fd;
  207. X{
  208. X    /** Save a string option to the file... only subtlety is when we
  209. X        save strings with spaces in 'em - translate to underscores!
  210. X    **/
  211. X
  212. X    register int i;
  213. X    char     buffer[SLEN];
  214. X    
  215. X    add_comment(iindex, fd);
  216. X    
  217. X    strcpy(buffer, value);
  218. X
  219. X    if (underscores)
  220. X      for (i=0; i < strlen(buffer); i++)
  221. X        if (buffer[i] == SPACE) buffer[i] = '_';
  222. X
  223. X    fprintf(fd, "%s = %s\n\n", save_info[iindex].name, buffer);
  224. X}
  225. X       
  226. Xsave_option_sort(iindex, fd)
  227. Xint iindex;
  228. XFILE *fd;
  229. X{
  230. X    /** save the current sorting option to a file **/
  231. X
  232. X    add_comment(iindex, fd);
  233. X
  234. X    fprintf(fd, "%s = %s\n\n", save_info[iindex].name,
  235. X        sort_name(SHORT));
  236. X}
  237. X
  238. Xsave_option_char(iindex, value, fd)
  239. Xint iindex;
  240. Xchar value;
  241. XFILE *fd;
  242. X{
  243. X    /** Save a character option to the file **/
  244. X
  245. X    add_comment(iindex, fd);
  246. X    
  247. X    fprintf(fd, "%s = %c\n\n", save_info[iindex].name, value);
  248. X}
  249. X
  250. Xsave_option_number(iindex, value, fd)
  251. Xint iindex, value;
  252. XFILE *fd;
  253. X{
  254. X    /** Save a binary option to the file - boy is THIS easy!! **/
  255. X
  256. X    add_comment(iindex, fd);
  257. X    
  258. X    fprintf(fd, "%s = %d\n\n", save_info[iindex].name, value);
  259. X}
  260. X
  261. Xsave_option_on_off(iindex, value, fd)
  262. Xint iindex, value;
  263. XFILE *fd;
  264. X{
  265. X    /** Save a binary option to the file - boy is THIS easy!! **/
  266. X
  267. X    add_comment(iindex, fd);
  268. X    
  269. X    fprintf(fd, "%s = %s\n\n", save_info[iindex].name, onoff(value));
  270. X}
  271. X
  272. Xsave_option_weedlist(iindex, fd)
  273. Xint iindex;
  274. XFILE *fd;
  275. X{
  276. X    /** save a list of weedout headers to the file **/
  277. X
  278. X    int length_so_far = 0, i;
  279. X
  280. X    add_comment(iindex, fd);
  281. X
  282. X    length_so_far = strlen(save_info[iindex].name) + 4;
  283. X
  284. X    fprintf(fd, "%s = ", save_info[iindex].name);
  285. X
  286. X    /** first off, skip till we get past the default list **/
  287. X
  288. X    for (i = 0; i < weedcount; i++) 
  289. X      if (strcmp(weedlist[i],"*end-of-defaults*") == 0)
  290. X        break;
  291. X
  292. X    while (i < weedcount) {
  293. X      if (strcmp(weedlist[i], "*end-of-defaults*") != 0)
  294. X        break;
  295. X      i++;    /* and get PAST it too! */
  296. X    }
  297. X
  298. X    while (i < weedcount) {
  299. X      if (strlen(weedlist[i]) + length_so_far > 78) {
  300. X        fprintf(fd, "\n\t");
  301. X        length_so_far = 8;
  302. X      }
  303. X      fprintf(fd, "\"%s\" ", weedlist[i]);
  304. X      length_so_far += (strlen(weedlist[i]) + 4);
  305. X      i++;
  306. X    }
  307. X    fprintf(fd, "\t\"*end-of-user-headers*\"\n\n");
  308. X}
  309. X
  310. Xsave_option_alternatives(iindex, list, fd)
  311. Xint iindex;
  312. Xstruct addr_rec *list;
  313. XFILE *fd;
  314. X{
  315. X    /** save a list of options to the file **/
  316. X    int length_so_far = 0;
  317. X    struct addr_rec     *alternate;
  318. X
  319. X    if (list == NULL) return;    /* nothing to do! */
  320. X
  321. X    add_comment(iindex, fd);
  322. X
  323. X    alternate = list;    /* don't LOSE the top!! */
  324. X
  325. X    length_so_far = strlen(save_info[iindex].name) + 4;
  326. X
  327. X    fprintf(fd, "%s = ", save_info[iindex].name);
  328. X
  329. X    while (alternate != NULL) {
  330. X      if (strlen(alternate->address) + length_so_far > 78) {
  331. X        fprintf(fd, "\n\t");
  332. X        length_so_far = 8;
  333. X      }
  334. X      fprintf(fd, "%s  ", alternate->address);
  335. X      length_so_far += (strlen(alternate->address) + 3);
  336. X      alternate = alternate->next;
  337. X    }
  338. X    fprintf(fd, "\n\n");
  339. X}
  340. X
  341. Xadd_comment(iindex, fd)
  342. Xint iindex;
  343. XFILE *fd;
  344. X{    
  345. X    /** get to and add the comment to the file **/
  346. X    char buffer[SLEN];
  347. X
  348. X    /** first off, add the comment from the comment file, if available **/
  349. X
  350. X    if (save_info[iindex].offset > 0L) {
  351. X      if (fseek(elminfo, save_info[iindex].offset, 0) == -1) {
  352. X        dprint(1,(debugfile,
  353. X           "** error %s seeking to %ld in elm-info file!\n",
  354. X           error_name(errno), save_info[iindex].offset));
  355. X      }
  356. X      else while (fgets(buffer, SLEN, elminfo) != NULL) {
  357. X        if (buffer[0] != '#') 
  358. X           break;
  359. X        else
  360. X           fprintf(fd, "%s", buffer);
  361. X      }
  362. X    }
  363. X}
  364. X
  365. Xbuild_offset_table(elminfo_fd)
  366. XFILE *elminfo_fd;
  367. X{
  368. X    /** read in the info file and build the table of offsets.
  369. X        This is a rather laborious puppy, but at least we can
  370. X        do a binary search through the array for each element and
  371. X        then we have it all at once!
  372. X    **/
  373. X
  374. X    char line_buffer[SLEN];
  375. X    
  376. X    while (fgets(line_buffer, SLEN, elminfo_fd) != NULL) {
  377. X      if (strlen(line_buffer) > 1)
  378. X        if (line_buffer[0] != '#' && !whitespace(line_buffer[0])) {
  379. X           no_ret(line_buffer);
  380. X           if (find_and_store_loc(line_buffer, ftell(elminfo_fd))) {
  381. X             dprint(1, (debugfile,"** Couldn't find and store \"%s\" **\n", 
  382. X             line_buffer));
  383. X           }
  384. X        }
  385. X    }
  386. X}
  387. X
  388. Xfind_and_store_loc(name, offset)
  389. Xchar *name;
  390. Xlong  offset;
  391. X{
  392. X    /** given the name and offset, find it in the table and store it **/
  393. X
  394. X    int first = 0, last, middle, compare;
  395. X
  396. X    last = NUMBER_OF_SAVEABLE_OPTIONS;
  397. X
  398. X    while (first <= last) {
  399. X
  400. X      middle = (first+last) / 2;
  401. X
  402. X      if ((compare = strcmp(name, save_info[middle].name)) < 0) /* a < b */
  403. X        last = middle - 1;
  404. X      else if (compare == 0) {                    /* a = b */
  405. X        save_info[middle].offset = offset;
  406. X        return(0);
  407. X      }
  408. X      else  /* greater */                        /* a > b */
  409. X        first = middle + 1; 
  410. X    }
  411. X
  412. X    return(-1);
  413. X}
  414. SHAR_EOF
  415. echo "File src/save_opts.c is complete"
  416. chmod 0444 src/save_opts.c || echo "restore of src/save_opts.c fails"
  417. echo "x - extracting src/savecopy.c (Text)"
  418. sed 's/^X//' << 'SHAR_EOF' > src/savecopy.c &&
  419. X
  420. Xstatic char rcsid[] = "@(#)$Id: savecopy.c,v 2.16 89/03/25 21:47:11 syd Exp $";
  421. X
  422. X/*******************************************************************************
  423. X *  The Elm Mail System  -  $Revision: 2.16 $   $State: Exp $
  424. X *
  425. X *             Copyright (c) 1986, 1987 Dave Taylor
  426. X *             Copyright (c) 1988, 1989 USENET Community Trust
  427. X *******************************************************************************
  428. X * Bug reports, patches, comments, suggestions should be sent to:
  429. X *
  430. X *    Syd Weinstein, Elm Coordinator
  431. X *    elm@dsinc.UUCP            dsinc!elm
  432. X *
  433. X *******************************************************************************
  434. X * $Log:    savecopy.c,v $
  435. X * Revision 2.16  89/03/25  21:47:11  syd
  436. X * Initial 2.2 Release checkin
  437. X * 
  438. X *
  439. X ******************************************************************************/
  440. X
  441. X/** Save a copy of the specified message in a folder.
  442. X
  443. X**/
  444. X
  445. X#include "headers.h"
  446. X#ifdef TMINSYS
  447. X# include <sys/time.h>
  448. X#else
  449. X# include <time.h>
  450. X#endif
  451. X
  452. X#include <errno.h>
  453. X
  454. Xchar *format_long();
  455. Xchar *error_name(), *error_description();
  456. Xchar *ctime();
  457. X
  458. Xextern char in_reply_to[SLEN];    /* In-Reply-To: string */
  459. Xextern int errno;
  460. X
  461. Xchar *strcat(), *strcpy();
  462. Xunsigned long sleep();
  463. Xlong  time();
  464. X
  465. Xsave_copy(to, cc, bcc, filename, copy_file, form)
  466. Xchar *to, *cc, *bcc, *filename, *copy_file;
  467. Xint form;
  468. X{
  469. X    /** This routine appends a copy of the outgoing message to the
  470. X        file specified.  **/
  471. X
  472. X    FILE *save,        /* file id for file to save to */
  473. X         *message,        /* file id for file with message body */
  474. X         *write_header_info();
  475. X    char  buffer[SLEN],    /* read buffer                */
  476. X          savename[SLEN];    /* name of file saving into    */
  477. X    static char helpmsg[LONG_STRING];
  478. X  
  479. X
  480. X    /* presume copy_file is okay as is for now */
  481. X    strcpy(savename, copy_file);
  482. X
  483. X    /* if save-by-name wanted */
  484. X    if(strcmp(copy_file, "=") == 0) {
  485. X
  486. X      get_return_name(to, buffer, TRUE);    /* determine 'to' login */
  487. X      if (strlen(buffer) == 0) {
  488. X
  489. X        /* can't get file name from 'to' -- use sent_mail instead */
  490. X        dprint(3, (debugfile,
  491. X        "Warning: get_return_name couldn't break down %s\n", to));
  492. X        error1(
  493. X"Cannot determine `to' name to save by! Saving to \"sent\" folder %s instead.",
  494. X          sent_mail);
  495. X        strcpy(savename, "<");
  496. X        sleep(3);
  497. X      } else
  498. X        sprintf(savename, "=%s", buffer);        /* good! */
  499. X    }
  500. X
  501. X    expand_filename(savename, TRUE);    /* expand special chars */
  502. X
  503. X    if ((errno = can_open(savename, "a"))) {
  504. X      dprint(2, (debugfile,
  505. X      "Error: attempt to autosave to a file that can't be appended to!\n"));
  506. X      dprint(2, (debugfile, "\tfilename = \"%s\"\n", savename));
  507. X      dprint(2, (debugfile, "** %s - %s **\n", error_name(errno),
  508. X          error_description(errno)));
  509. X
  510. X      /* Lets try sent_mail before giving up */
  511. X      if(strcmp(sent_mail, savename) == 0) {
  512. X        /* we are ALREADY using sent_mail! */
  513. X        error1("Cannot save to %s!", savename);
  514. X        sleep(3);
  515. X        return(FALSE);
  516. X      }
  517. X
  518. X      if ((errno = can_open(sent_mail, "a"))) {
  519. X        dprint(2, (debugfile,
  520. X      "Error: attempt to autosave to a file that can't be appended to!\n"));
  521. X        dprint(2, (debugfile, "\tfilename = \"%s\"\n", sent_mail));
  522. X        dprint(2, (debugfile, "** %s - %s **\n", error_name(errno),
  523. X            error_description(errno)));
  524. X        error2("Cannot save to %s nor to \"sent\" folder %s!",
  525. X            savename, sent_mail);
  526. X        sleep(3);
  527. X        return(FALSE);
  528. X      }
  529. X      error2("Cannot save to %s! Saving to \"sent\" folder %s instead.",
  530. X          savename, sent_mail);
  531. X      sleep(3);
  532. X      strcpy(savename, sent_mail);
  533. X    }
  534. X
  535. X    save_file_stats(savename);
  536. X
  537. X    /* Write header */
  538. X    if ((save = write_header_info(savename, to, cc, bcc,
  539. X          form == YES, TRUE)) == NULL)
  540. X      return(FALSE);
  541. X
  542. X    /* Now add file with message as handed to mailer */
  543. X    if ((message = fopen(filename, "r")) == NULL) {
  544. X      fclose(save);
  545. X      dprint(1, (debugfile,
  546. X         "Error: Couldn't read folder %s (save_copy)\n", filename));
  547. X      dprint(1, (debugfile, "** %s - %s **\n", error_name(errno),
  548. X          error_description(errno)));
  549. X      error1("Couldn't read folder %s!", filename);
  550. X      sleep(3);
  551. X      return(FALSE);
  552. X    }
  553. X
  554. X        copy_message_across(message, save, TRUE);
  555. X
  556. X    fclose(save);
  557. X    fclose(message);
  558. X
  559. X    restore_file_stats(savename);
  560. X
  561. X    return(TRUE);
  562. X}
  563. Xchar *
  564. Xcf_english(fn)
  565. Xchar *fn;
  566. X{
  567. X    /** Return "English" expansion for special copy file name abbreviations
  568. X    or just the file name  **/
  569. X
  570. X    if(!*fn)
  571. X      return("<no save>");
  572. X    else if(!fn[1]) {
  573. X      if(*fn == '=')
  574. X    return("<save by name>");
  575. X      else if(*fn == '<')
  576. X    return("<\"sent\" folder>");
  577. X    }
  578. X    return(fn);
  579. X}
  580. X
  581. X#define NCF_PROMPT    "Save copy in (use '?' for help/to list folders): "
  582. Xint
  583. Xname_copy_file(fn)
  584. Xchar *fn;
  585. X{
  586. X    /** Prompt user for name of file for saving copy of outbound msg to.
  587. X    Return true if we need a redraw. **/
  588. X
  589. X    int redraw = 0;    /* set when we ask for help = need redraw */
  590. X    char buffer[SLEN], origbuffer[SLEN];
  591. X    static char helpmsg[LONG_STRING];
  592. X
  593. X    /* expand passed copy file name into English */
  594. X    strcpy(buffer, cf_english(fn));
  595. X
  596. X    /* prepare screen with instructions */
  597. X    MoveCursor(LINES-2, 0);
  598. X    CleartoEOS();
  599. X    PutLine0(LINES-2, 0, NCF_PROMPT);
  600. X
  601. X    while(1) {
  602. X
  603. X      /* get file name from user input */
  604. X      strcpy(origbuffer, buffer);
  605. X      optionally_enter(buffer, LINES-2, strlen(NCF_PROMPT), FALSE, FALSE);
  606. X
  607. X      if(strcmp(buffer, "?") != 0) { /* got what we wanted - non-help choice */
  608. X
  609. X    if(strcmp(origbuffer, buffer) != 0)
  610. X      /* user changed from our English expansion 
  611. X       * so we'd better copy user input to fn
  612. X       */
  613. X      strcpy(fn, buffer);
  614. X
  615. X    /* else user presumably left our English expansion - no change in fn */
  616. X
  617. X    /* display English expansion of new user input a while */
  618. X    PutLine1(LINES-2, strlen(NCF_PROMPT), cf_english(fn));
  619. X    MoveCursor(LINES, 0);
  620. X    sleep(1);
  621. X    MoveCursor(LINES-2, 0);
  622. X    CleartoEOS();
  623. X
  624. X    return(redraw);
  625. X      }
  626. X
  627. X      /* give help and list folders */
  628. X      redraw = TRUE;
  629. X      if(!*helpmsg)     /* help message not yet formulated */
  630. X    sprintf(helpmsg, "%s%s%s%s%s%s%s%s",
  631. X          "\n\r\n\rEnter: <nothing> to not save a copy of the message,\n\r",
  632. X      "       '=' to save by name",
  633. X      " (depends upon whom the message is to, in the end),\n\r",
  634. X      "       '<' to save in your \"sent\" folder (", sent_mail, "),\n\r",
  635. X      "       or a filename",
  636. X      " (leading '=' denotes your folder directory).\n\r");
  637. X      list_folders(4, helpmsg);
  638. X      PutLine0(LINES-2, 0, NCF_PROMPT);
  639. X
  640. X      /* restore as default to English version of the passed copy file name */
  641. X      strcpy(buffer, cf_english(fn));
  642. X
  643. X    }
  644. X}
  645. SHAR_EOF
  646. chmod 0444 src/savecopy.c || echo "restore of src/savecopy.c fails"
  647. echo "x - extracting src/screen.c (Text)"
  648. sed 's/^X//' << 'SHAR_EOF' > src/screen.c &&
  649. X
  650. Xstatic char rcsid[] = "@(#)$Id: screen.c,v 2.22 89/03/25 21:47:17 syd Exp $";
  651. X
  652. X/*******************************************************************************
  653. X *  The Elm Mail System  -  $Revision: 2.22 $   $State: Exp $
  654. X *
  655. X *             Copyright (c) 1986, 1987 Dave Taylor
  656. X *             Copyright (c) 1988, 1989 USENET Community Trust
  657. X *******************************************************************************
  658. X * Bug reports, patches, comments, suggestions should be sent to:
  659. X *
  660. X *    Syd Weinstein, Elm Coordinator
  661. X *    elm@dsinc.UUCP            dsinc!elm
  662. X *
  663. X *******************************************************************************
  664. X * $Log:    screen.c,v $
  665. X * Revision 2.22  89/03/25  21:47:17  syd
  666. X * Initial 2.2 Release checkin
  667. X * 
  668. X *
  669. X ******************************************************************************/
  670. X
  671. X/**  screen display routines for ELM program 
  672. X
  673. X**/
  674. X
  675. X#include "headers.h"
  676. X
  677. X#define  minimum(a,b)    ((a) < (b) ? (a) : (b))
  678. X
  679. Xstatic   int  last_current     = -1;
  680. X
  681. Xchar *strcpy(), *strncpy(), *nameof(), *show_status();
  682. X
  683. Xextern char version_buff[];
  684. X
  685. Xshowscreen()
  686. X{
  687. X
  688. X    ClearScreen();
  689. X
  690. X    update_title();
  691. X
  692. X    last_header_page = -1;         /* force a redraw regardless */
  693. X    show_headers();
  694. X
  695. X    if (mini_menu)
  696. X      show_menu();
  697. X
  698. X    show_last_error();
  699. X    
  700. X    if (hp_terminal) 
  701. X      define_softkeys(MAIN);
  702. X}
  703. X
  704. Xupdate_title()
  705. X{
  706. X    /** display a new title line, probably due to new mail arriving **/
  707. X
  708. X    char buffer[SLEN];
  709. X
  710. X    if (selected)
  711. X      sprintf(buffer, 
  712. X          "%s is '%s' with %d shown out of %d [ELM %s]",
  713. X          (folder_type == SPOOL ? "Mailbox" : "Folder"),
  714. X          nameof(cur_folder), selected, message_count, version_buff);
  715. X    else
  716. X      sprintf(buffer, "%s is '%s' with %d message%s [ELM %s]",
  717. X          (folder_type == SPOOL ? "Mailbox" : "Folder"),
  718. X          nameof(cur_folder), message_count,
  719. X          plural(message_count), version_buff);
  720. X
  721. X    ClearLine(1);
  722. X
  723. X    Centerline(1, buffer);
  724. X}
  725. X
  726. Xshow_menu()
  727. X{
  728. X    /** write main system menu... **/
  729. X
  730. X    if (user_level == 0) {    /* a rank beginner.  Give less options  */
  731. X      Centerline(LINES-7,
  732. X  "You can use any of the following commands by pressing the first character;");
  733. X          Centerline(LINES-6,
  734. X"d)elete or u)ndelete mail,  m)ail a message,  r)eply or f)orward mail,  q)uit");
  735. X      Centerline(LINES-5,
  736. X  "To read a message, press <return>.  j = move down, k = move up, ? = help");
  737. X    } else {
  738. X    Centerline(LINES-7,
  739. X  "|=pipe, !=shell, ?=help, <n>=set current to n, /=search pattern");
  740. X        Centerline(LINES-6,
  741. X"a)lias, C)opy, c)hange folder, d)elete, e)dit, f)orward, g)roup reply, m)ail,"
  742. X); 
  743. X    Centerline(LINES-5,
  744. X  "n)ext, o)ptions, p)rint, r)eply, s)ave, t)ag, q)uit, u)ndelete, or e(x)it");
  745. X    }
  746. X}
  747. X
  748. Xint
  749. Xshow_headers()
  750. X{
  751. X    /** Display page of headers (10) if present.  First check to 
  752. X        ensure that header_page is in bounds, fixing silently if not.
  753. X        If out of bounds, return zero, else return non-zero 
  754. X        Modified to only show headers that are "visible" to ze human
  755. X        person using ze program, eh?
  756. X    **/
  757. X
  758. X    register int this_msg = 0, line = 4, last = 0, last_line, 
  759. X             displayed = 0, using_to;
  760. X    char newfrom[SLEN], buffer[SLEN];
  761. X    
  762. X    if (fix_header_page())
  763. X      return(FALSE);
  764. X
  765. X    if (selected) {
  766. X      if ((header_page*headers_per_page) > selected)
  767. X        return(FALSE);     /* too far! too far! */
  768. X
  769. X      this_msg = visible_to_index(header_page * headers_per_page + 1);
  770. X      displayed = header_page * headers_per_page;
  771. X
  772. X      last = displayed+headers_per_page;
  773. X
  774. X    }
  775. X    else {
  776. X      if (header_page == last_header_page)     /* nothing to do! */
  777. X        return(FALSE);
  778. X
  779. X      /** compute last header to display **/
  780. X  
  781. X      this_msg = header_page * headers_per_page;
  782. X      last = this_msg + (headers_per_page - 1);
  783. X    }
  784. X
  785. X    if (last >= message_count) last = message_count-1;
  786. X
  787. X    /** Okay, now let's show the header page! **/
  788. X
  789. X    ClearLine(line);    /* Clear the top line... */
  790. X
  791. X    MoveCursor(line, 0);    /* and move back to the top of the page... */
  792. X
  793. X    while ((selected && displayed < last) || this_msg <= last) {
  794. X      using_to = tail_of(headers[this_msg]->from, newfrom,
  795. X        headers[this_msg]->to); 
  796. X
  797. X      if (this_msg == current-1) 
  798. X        build_header_line(buffer, headers[this_msg], this_msg+1,
  799. X                TRUE, newfrom, using_to);
  800. X      else
  801. X        build_header_line(buffer, headers[this_msg], 
  802. X                this_msg+1, FALSE, newfrom, using_to);
  803. X      if (selected) 
  804. X        displayed++;
  805. X
  806. X      if (this_msg == current-1 && has_highlighting && ! arrow_cursor) {
  807. X          StartInverse();
  808. X          Write_to_screen("%s\n\r", 1, buffer);    /* avoid '%' probs */
  809. X          EndInverse();
  810. X      } else
  811. X          Write_to_screen("%s\n\r", 1, buffer);    /* avoid '%' probs */
  812. X      CleartoEOLN();
  813. X      line++;        /* for clearing up in a sec... */
  814. X
  815. X      if (selected) {
  816. X        if ((this_msg = next_message(this_msg, FALSE)) < 0)
  817. X          break;    /* GET OUTTA HERE! */
  818. X
  819. X        /* the preceeding looks gross because we're using an INDEX
  820. X           variable to pretend to be a "current" counter, and the 
  821. X           current counter is always 1 greater than the actual 
  822. X           index.  Does that make sense??
  823. X         */
  824. X      }
  825. X      else
  826. X        this_msg++;                    /* even dumber...  */
  827. X    }
  828. X
  829. X    /* clear unused lines */
  830. X
  831. X    if (mini_menu)
  832. X      last_line = LINES-8;
  833. X    else
  834. X      last_line = LINES-4;
  835. X
  836. X    while (line < last_line) {
  837. X      CleartoEOLN();
  838. X      NewLine();
  839. X      line++;
  840. X    }
  841. X
  842. X    display_central_message();
  843. X
  844. X    last_current = current;
  845. X    last_header_page = header_page;
  846. X
  847. X    return(TRUE);
  848. X}
  849. X
  850. Xshow_current()
  851. X{
  852. X    /** Show the new header, with all the usual checks **/
  853. X
  854. X    register int first = 0, last = 0, last_line, new_line, using_to;
  855. X    char     newfrom[SLEN], old_buffer[SLEN], new_buffer[SLEN];
  856. X
  857. X    (void) fix_header_page();    /* Who cares what it does? ;-) */
  858. X
  859. X    /** compute the first and last header on this page **/
  860. X    first = header_page * headers_per_page + 1;
  861. X    last  = first + (headers_per_page - 1);
  862. X
  863. X    /* if not a full page adjust last to be the real last */
  864. X    if (selected && last > selected)
  865. X      last = selected;
  866. X    if (!selected && last > message_count) 
  867. X      last = message_count;
  868. X
  869. X    /** okay, now let's show the pointers... **/
  870. X
  871. X    /** have we changed??? **/
  872. X    if (current == last_current) 
  873. X      return;
  874. X
  875. X    if (selected) {
  876. X      last_line = ((compute_visible(last_current)-1) %
  877. X             headers_per_page)+4;
  878. X      new_line  = ((compute_visible(current)-1) % headers_per_page)+4;
  879. X    } else {
  880. X      last_line = ((last_current-1) % headers_per_page)+4;
  881. X      new_line  = ((current-1) % headers_per_page)+4;
  882. X    }
  883. X    
  884. X    if (has_highlighting && ! arrow_cursor) {
  885. X  
  886. X      using_to = tail_of(headers[current-1]->from, newfrom,
  887. X        headers[current-1]->to); 
  888. X      build_header_line(new_buffer, headers[current-1],  current,
  889. X          TRUE, newfrom, using_to);
  890. X
  891. X      /* clear last current if it's in proper range */
  892. X      if (last_current > 0        /* not a dummy value */
  893. X          && compute_visible(last_current) <= last
  894. X          && compute_visible(last_current) >= first) {
  895. X
  896. X        dprint(5, (debugfile, 
  897. X          "\nlast_current = %d ... clearing [1] before we add [2]\n", 
  898. X           last_current));
  899. X        dprint(5, (debugfile, "first = %d, and last = %d\n\n",
  900. X          first, last));
  901. X
  902. X        using_to = tail_of(headers[last_current-1]->from, newfrom,
  903. X          headers[last_current-1]->to); 
  904. X        build_header_line(old_buffer, headers[last_current-1], 
  905. X         last_current, FALSE, newfrom, using_to);
  906. X
  907. X        ClearLine(last_line);
  908. X        PutLine0(last_line, 0, old_buffer);
  909. X      }
  910. X      MoveCursor(new_line, 0);
  911. X      StartInverse();
  912. X      Write_to_screen("%s", 1, new_buffer);
  913. X      EndInverse();
  914. X    }
  915. X    else {
  916. X      if (on_page(last_current-1)) 
  917. X        PutLine0(last_line,0,"  ");    /* remove old pointer... */
  918. X      if (on_page(current-1))
  919. X        PutLine0(new_line, 0,"->");
  920. X    }
  921. X    
  922. X    last_current = current;
  923. X}
  924. X
  925. Xbuild_header_line(buffer, entry, message_number, highlight, from, really_to)
  926. Xchar *buffer;
  927. Xstruct header_rec *entry;
  928. Xint message_number, highlight, really_to;
  929. Xchar *from;
  930. X{
  931. Xchar *strchr();
  932. X
  933. X    /** Build in buffer the message header ... entry is the current
  934. X        message entry, 'from' is a modified (displayable) from line, 
  935. X        'highlight' is either TRUE or FALSE, and 'message_number'
  936. X        is the number of the message.
  937. X    **/
  938. X
  939. X    /** Note: using 'strncpy' allows us to output as much of the
  940. X        subject line as possible given the dimensions of the screen.
  941. X        The key is that 'strncpy' returns a 'char *' to the string
  942. X        that it is handing to the dummy variable!  Neat, eh? **/
  943. X    
  944. X    int who_width = 18, subj_width;
  945. X    char *dot = strchr(from, '.');
  946. X    char *bang = strchr(from, '!');
  947. X
  948. X    /* truncate 'from' to 18 characters -
  949. X     * this includes the leading "To" if really_to is true.
  950. X     * Note:
  951. X     *    'from' is going to be of three forms
  952. X     *        - full name (truncate on the right for readability)
  953. X     *        - logname@machine (truncate on the right to preserve
  954. X     *            logname over machine name
  955. X     *        - machine!logname -- a more complex situation
  956. X     *            If this form doesn't fit, either machine
  957. X     *            or logname are long. If logname is long,
  958. X     *            we can stand to loose part of it, so we
  959. X     *            truncate on the right. If machine name is
  960. X     *            long, we'd better truncate on the left,
  961. X     *            to insure we get the logname. Now if the
  962. X     *            machine name is long, it will have "." in
  963. X     *            it.
  964. X     *    Therfore, we truncate on the left if there is a "." and a "!"
  965. X     *    in 'from', else we truncate on the right.
  966. X     */
  967. X
  968. X    /* Note that one huge sprintf() is too hard for some compilers. */
  969. X    sprintf(buffer, "%s%s%c%-3d %3.3s %-2d ",
  970. X        (highlight && arrow_cursor)? "->" : "  ",
  971. X        show_status(entry->status),
  972. X        (entry->status & TAGGED?  '+' : ' '),
  973. X            message_number,
  974. X            entry->month, 
  975. X        atoi(entry->day));
  976. X
  977. X    /* show "To " in a way that it can never be truncated. */
  978. X    if (really_to) {
  979. X      strcat(buffer, "To ");
  980. X      who_width -= 3;
  981. X    }
  982. X
  983. X    /* truncate 'from' on left if needed.
  984. X     * sprintf will truncate on right afterward if needed. */
  985. X    if ((strlen(from) > who_width) && dot && bang && (dot < bang)) {
  986. X      from += (strlen(from) - who_width);
  987. X    }
  988. X
  989. X    /* Set the subject display width.
  990. X     * If it is too long, truncate it to fit.
  991. X     * If it is highlighted but not with the arrow  cursor,
  992. X     * expand it to fit so that the reverse video bar extends
  993. X     * aesthetically the full length of the line.
  994. X     */
  995. X    if ((highlight && !arrow_cursor)
  996. X        || (COLUMNS-44 < (subj_width =strlen(entry->subject))))
  997. X        subj_width = COLUMNS-44;
  998. X
  999. X    /* complete line with sender, length and subject. */
  1000. X    sprintf(buffer + strlen(buffer), "%-*.*s (%d) %s%-*.*s",
  1001. X        /* give max and min width parameters for 'from' */
  1002. X        who_width,
  1003. X        who_width,
  1004. X        from,
  1005. X
  1006. X        entry->lines, 
  1007. X        (entry->lines / 1000   > 0? ""   :    /* spacing the  */
  1008. X          entry->lines / 100   > 0? " "  :    /* same for the */
  1009. X            entry->lines / 10  > 0? "  " :    /* lines in ()  */
  1010. X                                    "   "),     /*   [wierd]    */
  1011. X
  1012. X        subj_width, subj_width, entry->subject);
  1013. X}
  1014. X
  1015. Xint
  1016. Xfix_header_page()
  1017. X{
  1018. X    /** this routine will check and ensure that the current header
  1019. X        page being displayed contains messages!  It will silently
  1020. X        fix 'header-page' if wrong.  Returns TRUE if changed.  **/
  1021. X
  1022. X    int last_page, old_header;
  1023. X
  1024. X    old_header = header_page;
  1025. X
  1026. X    last_page = (int) ((message_count-1) / headers_per_page);
  1027. X    if (header_page > last_page) 
  1028. X      header_page = last_page;
  1029. X    else if (header_page < 0) 
  1030. X          header_page = 0;
  1031. X
  1032. X    return(old_header != header_page);
  1033. X}
  1034. X
  1035. Xint
  1036. Xon_page(message)
  1037. Xint message;
  1038. X{
  1039. X    /** Returns true iff the specified message is on the displayed page. **/
  1040. X
  1041. X    if (selected) message = compute_visible(message);
  1042. X
  1043. X    if (message >= header_page * headers_per_page)
  1044. X      if (message < ((header_page+1) * headers_per_page))
  1045. X        return(TRUE);
  1046. X
  1047. X    return(FALSE);
  1048. X}
  1049. X
  1050. Xchar *show_status(status)
  1051. Xint status;
  1052. X{
  1053. X    /** This routine returns a pair of characters indicative of
  1054. X        the status of this message.  The first character represents
  1055. X        the interim status of the message (e.g. the status within 
  1056. X        the mail system):
  1057. X
  1058. X        E = Expired message
  1059. X        N = New message
  1060. X        O = Unread old message    dsi mailx emulation addition
  1061. X        D = Deleted message
  1062. X        _ = (space) default 
  1063. X
  1064. X        and the second represents the permanent attributes of the
  1065. X        message:
  1066. X
  1067. X        C = Company Confidential message
  1068. X            U = Urgent (or Priority) message
  1069. X        P = Private message
  1070. X        A = Action associated with message
  1071. X        F = Form letter
  1072. X        _ = (space) default
  1073. X    **/
  1074. X
  1075. X    static char mybuffer[3];
  1076. X
  1077. X    /** the first character, please **/
  1078. X
  1079. X         if (status & DELETED)    mybuffer[0] = 'D';
  1080. X    else if (status & EXPIRED)    mybuffer[0] = 'E';
  1081. X    else if (status & NEW)        mybuffer[0] = 'N';
  1082. X    else if (status & UNREAD)    mybuffer[0] = 'O';
  1083. X    else                            mybuffer[0] = ' ';
  1084. X
  1085. X    /** and the second... **/
  1086. X
  1087. X         if (status & CONFIDENTIAL) mybuffer[1] = 'C';
  1088. X    else if (status & URGENT)       mybuffer[1] = 'U';
  1089. X    else if (status & PRIVATE)      mybuffer[1] = 'P';
  1090. X    else if (status & ACTION)       mybuffer[1] = 'A';
  1091. X    else if (status & FORM_LETTER)  mybuffer[1] = 'F';
  1092. X    else                     mybuffer[1] = ' ';
  1093. X
  1094. X    mybuffer[2] = '\0';
  1095. X
  1096. X    return( (char *) mybuffer);
  1097. X}
  1098. SHAR_EOF
  1099. chmod 0444 src/screen.c || echo "restore of src/screen.c fails"
  1100. echo "x - extracting src/showmsg.c (Text)"
  1101. sed 's/^X//' << 'SHAR_EOF' > src/showmsg.c &&
  1102. X
  1103. Xstatic char rcsid[] = "@(#)$Id: showmsg.c,v 2.21 89/03/25 21:47:19 syd Exp $";
  1104. X
  1105. X/*******************************************************************************
  1106. X *  The Elm Mail System  -  $Revision: 2.21 $   $State: Exp $
  1107. X *
  1108. X *             Copyright (c) 1986, 1987 Dave Taylor
  1109. X *             Copyright (c) 1988, 1989 USENET Community Trust
  1110. X *******************************************************************************
  1111. X * Bug reports, patches, comments, suggestions should be sent to:
  1112. X *
  1113. X *    Syd Weinstein, Elm Coordinator
  1114. X *    elm@dsinc.UUCP            dsinc!elm
  1115. X *
  1116. X *******************************************************************************
  1117. X * $Log:    showmsg.c,v $
  1118. X * Revision 2.21  89/03/25  21:47:19  syd
  1119. X * Initial 2.2 Release checkin
  1120. X * 
  1121. X *
  1122. X ******************************************************************************/
  1123. X
  1124. X/** This file contains all the routines needed to display the specified
  1125. X    message.
  1126. X**/
  1127. X
  1128. X#include "headers.h"
  1129. X#include <ctype.h>
  1130. X#include <errno.h>
  1131. X
  1132. X#ifdef BSD
  1133. X# include <sys/wait.h>
  1134. X# undef       tolower
  1135. X#endif
  1136. X
  1137. Xextern int errno;
  1138. X
  1139. Xchar *error_name(), *strcat(), *strcpy();
  1140. Xvoid   _exit();
  1141. X
  1142. Xint    memory_lock = FALSE;    /* is it available?? */
  1143. Xint    pipe_abort  = FALSE;    /* did we receive a SIGNAL(SIGPIPE)? */
  1144. X
  1145. XFILE *pipe_wr_fp;        /* file pointer to write to external pager */
  1146. Xextern int lines_displayed,    /* defined in "builtin" */    
  1147. X       lines_put_on_screen;    /*    ditto too!        */
  1148. X
  1149. Xint
  1150. Xshow_msg(number)
  1151. Xint number;
  1152. X{
  1153. X    /*** Display number'th message.  Get starting and ending lines
  1154. X         of message from headers data structure, then fly through
  1155. X         the file, displaying only those lines that are between the
  1156. X         two!
  1157. X
  1158. X         Return 0 to return to the index screen or a character entered
  1159. X         by the user to initiate a command without returning to
  1160. X         the index screen (to be processed via process_showmsg_cmd()).
  1161. X    ***/
  1162. X
  1163. X    char title1[SLEN], title2[SLEN], title3[SLEN], titlebuf[SLEN];
  1164. X    char who[LONG_STRING], buffer[VERY_LONG_STRING];
  1165. X#ifdef BSD
  1166. X    union wait wait_stat;
  1167. X#else
  1168. X    int wait_stat;
  1169. X#endif
  1170. X
  1171. X    int crypted = 0;            /* encryption */
  1172. X    int weed_header, weeding_out = 0;    /* weeding    */ 
  1173. X    int using_to,                /* misc use   */
  1174. X        pipe_fd[2],                /* pipe file descriptors */
  1175. X        new_pipe_fd,            /* dup'ed pipe fil des */
  1176. X        lines,                /* num lines in msg */
  1177. X        fork_ret,                /* fork return value */
  1178. X        wait_ret,                /* wait return value */
  1179. X        form_letter = FALSE,        /* Form ltr?  */
  1180. X        form_letter_section = 0,        /* section    */
  1181. X        padding = 0,            /*   counter  */
  1182. X        builtin = FALSE,            /* our pager? */
  1183. X        val = 0,                /* return val */
  1184. X        buf_len,                /* line length */
  1185. X        whole_line;                /* whole line */
  1186. X    struct header_rec *current_header = headers[number-1];
  1187. X
  1188. X
  1189. X    lines = current_header->lines; 
  1190. X
  1191. X    dprint(4, (debugfile,"displaying %d lines from message %d using %s\n", 
  1192. X        lines, number, pager));
  1193. X
  1194. X    if (number > message_count || number < 1)
  1195. X      return(val);
  1196. X
  1197. X    if(ison(current_header->status, NEW)) {
  1198. X      clearit(current_header->status, NEW);   /* it's been read now! */
  1199. X      current_header->status_chgd = TRUE;
  1200. X    }
  1201. X    if(ison(current_header->status, UNREAD)) {
  1202. X      clearit(current_header->status, UNREAD);   /* it's been read now! */
  1203. X      current_header->status_chgd = TRUE;
  1204. X    }
  1205. X
  1206. X    memory_lock = FALSE;
  1207. X
  1208. X    /* some explanation for that last one - We COULD use memory locking
  1209. X       to speed up the paging, but the action of "ClearScreen" on a screen
  1210. X       with memory lock turned on seems to vary considerably (amazingly so)
  1211. X       so it's safer to only allow memory lock to be a viable bit of
  1212. X       trickery when dumping text to the screen in scroll mode.
  1213. X       Philosophical arguments should be forwarded to Bruce at the 
  1214. X       University of Walamazoo, Australia, via ACSNet  *wry chuckle* */
  1215. X
  1216. X    if (fseek(mailfile, current_header->offset, 0) == -1) {
  1217. X      dprint(1, (debugfile,
  1218. X          "Error: seek %d bytes into file, errno %s (show_message)\n",
  1219. X          current_header->offset, error_name(errno)));
  1220. X      error2("ELM failed seeking %d bytes into file (%s).",
  1221. X          current_header->offset, error_name(errno));    
  1222. X      return(val);
  1223. X    }
  1224. X    if(current_header->encrypted)
  1225. X      getkey(OFF);
  1226. X
  1227. X    if(builtin=(first_word(pager,"builtin")||first_word(pager,"internal")))
  1228. X
  1229. X      start_builtin(lines);
  1230. X
  1231. X    else {
  1232. X
  1233. X      /* put terminal out of raw mode so external pager has normal env */
  1234. X      Raw(OFF);
  1235. X
  1236. X      /* create pipe for external pager and fork */
  1237. X
  1238. X      if(pipe(pipe_fd) == -1) {
  1239. X        dprint(1, (debugfile, "Error: pipe failed, errno %s (show_msg)\n",
  1240. X          error_name(errno)));
  1241. X        error1("Could not prepare for external pager(pipe()-%s).",
  1242. X          error_name(errno));    
  1243. X        Raw(ON);
  1244. X        return(val);
  1245. X      }
  1246. X
  1247. X      if((fork_ret = fork()) == -1) {
  1248. X
  1249. X        dprint(1, (debugfile, "Error: fork failed, errno %s (show_msg)\n",
  1250. X          error_name(errno)));
  1251. X        error1("Could not prepare for external pager(fork()-%s).",
  1252. X          error_name(errno));    
  1253. X        Raw(ON);
  1254. X        return(val);
  1255. X
  1256. X      } else if (fork_ret == 0) {
  1257. X
  1258. X        /* child fork */
  1259. X
  1260. X        /* close write-only pipe fd and fit read-only pipe fd to stdin */
  1261. X
  1262. X        close(pipe_fd[1]);
  1263. X        close(fileno(stdin));
  1264. X        if((new_pipe_fd = dup(pipe_fd[0])) == -1) {
  1265. X          dprint(1, (debugfile, "Error: dup failed, errno %s (show_msg)\n",
  1266. X        error_name(errno)));
  1267. X          error1("Could not prepare for external pager(dup()-%s).",
  1268. X        error_name(errno));    
  1269. X          _exit(errno);
  1270. X        }
  1271. X        close(pipe_fd[0]);    /* original pipe fd no longer needed */
  1272. X
  1273. X        /* use stdio on new pipe fd */
  1274. X        if(fdopen(new_pipe_fd, "r") == NULL) {
  1275. X          dprint(1,
  1276. X        (debugfile, "Error: child fdopen failed, errno %s (show_msg)\n",
  1277. X        error_name(errno)));
  1278. X          error1("Could not prepare for external pager(child fdopen()-%s).",
  1279. X        error_name(errno));    
  1280. X          _exit(errno);
  1281. X        }
  1282. X
  1283. X        /* now execute pager and exit */
  1284. X        
  1285. X        /* system_call() will return user to user's normal permissions.
  1286. X         * This is what makes this pipe secure - user won't have elm's
  1287. X         * special setgid permissions (if so configured) and will only
  1288. X         * be able to execute a pager that user normally has permission
  1289. X         * to execute */
  1290. X
  1291. X        _exit(system_call(pager, SH, TRUE));
  1292. X      
  1293. X      } /* else this is the parent fork */
  1294. X
  1295. X      /* close read-only pipe fd and do write-only with stdio */
  1296. X      close(pipe_fd[0]);
  1297. X
  1298. X      if((pipe_wr_fp = fdopen(pipe_fd[1], "w")) == NULL) {
  1299. X        dprint(1,
  1300. X          (debugfile, "Error: parent fdopen failed, errno %s (show_msg)\n",
  1301. X          error_name(errno)));
  1302. X        error1("Could not prepare for external pager(parent fdopen()-%s).",
  1303. X          error_name(errno));    
  1304. X
  1305. X        /* Failure - must close pipe and wait for child */
  1306. X        close(pipe_fd[1]);
  1307. X        while ((wait_ret = wait(&wait_stat)) != fork_ret && wait_ret!= -1)
  1308. X          ;
  1309. X
  1310. X        Raw(OFF);
  1311. X        return(val);    /* pager may have already touched the screen */
  1312. X      }
  1313. X
  1314. X      /* and that's it! */
  1315. X      lines_displayed = 0;
  1316. X    }
  1317. X
  1318. X    ClearScreen();
  1319. X
  1320. X    if (cursor_control) transmit_functions(OFF);
  1321. X
  1322. X    pipe_abort = FALSE;
  1323. X
  1324. X    if (form_letter = (current_header->status&FORM_LETTER)) {
  1325. X      if (filter)
  1326. X        form_letter_section = 1;    /* initialize to section 1 */
  1327. X    }
  1328. X
  1329. X    if (title_messages && filter) {
  1330. X
  1331. X      using_to =
  1332. X        tail_of(current_header->from, who, current_header->to);
  1333. X
  1334. X      sprintf(title1, "%s %d/%d  ",
  1335. X            headers[current-1]->status & DELETED ? "[deleted]" :
  1336. X            form_letter ? "Form": "Message",
  1337. X            number, message_count);
  1338. X      sprintf(title2, "%s %s", using_to? "To" : "From", who);
  1339. X      sprintf(title3, "  %s %s '%d at %s",
  1340. X                current_header->month, current_header->day, 
  1341. X               atoi(current_header->year), current_header->time);
  1342. X
  1343. X      /* truncate or pad title2 portion on the right
  1344. X       * so that line fits exactly */
  1345. X      padding =
  1346. X        COLUMNS -
  1347. X        (strlen(title1) + (buf_len=strlen(title2)) + strlen(title3));
  1348. X
  1349. X      sprintf(titlebuf, "%s%-*.*s%s\n", title1, buf_len+padding,
  1350. X          buf_len+padding, title2, title3);
  1351. X
  1352. X      if (builtin)
  1353. X        display_line(titlebuf);
  1354. X      else
  1355. X        fprintf(pipe_wr_fp, "%s", titlebuf);
  1356. X
  1357. X      /** if there's a subject, let's output it next,
  1358. X          centered if it fits on a single line.  **/
  1359. X
  1360. X      if ((buf_len = strlen(current_header->subject)) > 0 && 
  1361. X        matches_weedlist("Subject:")) {
  1362. X        padding = (buf_len < COLUMNS ? COLUMNS - buf_len : 0);
  1363. X        sprintf(buffer, "%*s%s\n", padding/2, "", current_header->subject);
  1364. X      } else
  1365. X        strcpy(buffer, "\n");
  1366. X
  1367. X      if (builtin)
  1368. X        display_line(buffer);
  1369. X      else
  1370. X        fprintf(pipe_wr_fp, "%s", buffer);
  1371. X      
  1372. X      /** was this message address to us?  if not, then to whom? **/
  1373. X
  1374. X      if (! using_to && matches_weedlist("To:") && filter &&
  1375. X          strcmp(current_header->to,username) != 0 &&
  1376. X          strlen(current_header->to) > 0) {
  1377. X        if (strlen(current_header->to) > 60)
  1378. X          sprintf(buffer, "%s(message addressed to %.60s)\n", 
  1379. X                strlen(current_header->subject) > 0 ? "\n" : "",
  1380. X            current_header->to);
  1381. X        else
  1382. X          sprintf(buffer, "%s(message addressed to %s)\n", 
  1383. X                strlen(current_header->subject) > 0 ? "\n" : "",
  1384. X            current_header->to);
  1385. X        if (builtin)
  1386. X          display_line(buffer);
  1387. X        else
  1388. X          fprintf(pipe_wr_fp, "%s", buffer);
  1389. X      }
  1390. X    
  1391. X      /** The test above is: if we didn't originally send the mail
  1392. X          (e.g. we're not reading "mail.sent") AND the user is currently
  1393. X          weeding out the "To:" line (otherwise they'll get it twice!)
  1394. X          AND the user is actually weeding out headers AND the message 
  1395. X          wasn't addressed to the user AND the 'to' address is non-zero 
  1396. X          (consider what happens when the message doesn't HAVE a "To:" 
  1397. X          line...the value is NULL but it doesn't match the username 
  1398. X          either.  We don't want to display something ugly like 
  1399. X          "(message addressed to )" which will just clutter up the 
  1400. X          screen!).
  1401. X
  1402. X          And you thought programming was EASY!!!!
  1403. X      **/
  1404. X
  1405. X      /** one more friendly thing - output a line indicating what sort
  1406. X          of status the message has (e.g. Urgent etc).  Mostly added
  1407. X          for X.400 support, this is nonetheless generally useful to
  1408. X          include...
  1409. X      **/
  1410. X
  1411. X      buffer[0] = '\0';
  1412. X
  1413. X      /* we want to flag Urgent, Confidential, Private and Expired tags */
  1414. X
  1415. X      if (current_header->status & PRIVATE)
  1416. X        strcpy(buffer, "\n(** This message is tagged Private");
  1417. X      else if (current_header->status & CONFIDENTIAL) 
  1418. X        strcpy(buffer, "\n(** This message is tagged Company Confidential");
  1419. X
  1420. X      if (current_header->status & URGENT) {
  1421. X        if (buffer[0] == '\0')
  1422. X          strcpy(buffer, "\n(** This message is tagged Urgent");
  1423. X        else if (current_header->status & EXPIRED)
  1424. X          strcat(buffer, ", Urgent");
  1425. X        else
  1426. X          strcat(buffer, " and Urgent");
  1427. X      }
  1428. X
  1429. X      if (current_header->status & EXPIRED) {
  1430. X        if (buffer[0] == '\0')
  1431. X          strcpy(buffer, "\n(** This message has Expired");
  1432. X        else
  1433. X          strcat(buffer, ", and has Expired");
  1434. X      }
  1435. X
  1436. X      if (buffer[0] != '\0') {
  1437. X        strcat(buffer, " **)\n");
  1438. X        if (builtin)
  1439. X          display_line(buffer);
  1440. X        else
  1441. X          fprintf(pipe_wr_fp, buffer);
  1442. X      }
  1443. X
  1444. X      if (builtin)            /* this is for a one-line blank    */
  1445. X        display_line("\n");        /*   separator between the title   */
  1446. X      else                /*   stuff and the actual message  */
  1447. X        fprintf(pipe_wr_fp, "\n");    /*   we're trying to display       */
  1448. X
  1449. X    }
  1450. X
  1451. X    weed_header = filter;    /* allow us to change it after header */
  1452. X
  1453. X    while (lines > 0 && pipe_abort == FALSE) {
  1454. X
  1455. X        if (fgets(buffer, VERY_LONG_STRING, mailfile) == NULL) {
  1456. X
  1457. X          dprint(1, (debugfile,
  1458. X        "Premature end of file! Lines left = %d msg = %s (show_msg)\n",
  1459. X        lines, number));
  1460. X
  1461. X          error("Premature end of file!");
  1462. X          sleep(2);
  1463. X          break;
  1464. X        }
  1465. X        if ((buf_len=strlen(buffer)) > 0)  {
  1466. X          if(buffer[buf_len - 1] == '\n')
  1467. X        whole_line = TRUE;
  1468. X          else
  1469. X        whole_line = FALSE;
  1470. X              no_ret(buffer);
  1471. X        }
  1472. X
  1473. X          if (strlen(buffer) == 0) {
  1474. X          weed_header = 0;        /* past header! */
  1475. X          weeding_out = 0;
  1476. X        }
  1477. X
  1478. X        if (form_letter && weed_header)
  1479. X        /* skip it.  NEVER display random headers in forms! */;
  1480. X        else if (weed_header && matches_weedlist(buffer)) 
  1481. X          weeding_out = 1;     /* aha!  We don't want to see this! */
  1482. X        else if (buffer[0] == '[') {
  1483. X          if (strcmp(buffer, START_ENCODE)==0)
  1484. X            crypted = ON;
  1485. X          else if (strcmp(buffer, END_ENCODE)==0)
  1486. X            crypted = OFF;
  1487. X          else if (crypted) {
  1488. X                encode(buffer);
  1489. X            val = show_line(buffer, builtin);
  1490. X          }
  1491. X          else
  1492. X            val = show_line(buffer, builtin);
  1493. X        } 
  1494. X        else if (crypted) {
  1495. X          encode(buffer);
  1496. X          val = show_line(buffer, builtin); 
  1497. X        }
  1498. X        else if (weeding_out) {
  1499. X          weeding_out = (whitespace(buffer[0]));    /* 'n' line weed */
  1500. X          if (! weeding_out)     /* just turned on! */
  1501. X            val = show_line(buffer, builtin);
  1502. X        } 
  1503. X        else if (form_letter && first_word(buffer,"***") && filter) {
  1504. X          strcpy(buffer,
  1505. X"\n------------------------------------------------------------------------------\n");
  1506. X          val = show_line(buffer, builtin);    /* hide '***' */
  1507. X          form_letter_section++;
  1508. X        }
  1509. X        else if (form_letter_section == 1 || form_letter_section == 3)
  1510. X          /** skip this stuff - we can't deal with it... **/;
  1511. X        else
  1512. X          val = show_line(buffer, builtin);
  1513. X    
  1514. X        if (val != 0)    /* discontinue the display */
  1515. X          break;
  1516. X
  1517. X        if(whole_line) lines--;
  1518. X        lines_displayed++;
  1519. X    }
  1520. X
  1521. X        if (cursor_control) transmit_functions(ON);
  1522. X
  1523. X    if (!builtin) {
  1524. X      fclose(pipe_wr_fp);
  1525. X      while ((wait_ret = wait(&wait_stat)) != fork_ret
  1526. X          && wait_ret!= -1)
  1527. X        ;
  1528. X      /* turn raw on **after** child terminates in case child
  1529. X       * doesn't put us back to cooked mode after we return ourselves
  1530. X       * to raw.
  1531. X       */
  1532. X      Raw(ON);
  1533. X    }
  1534. X
  1535. X    /* If we are to prompt for a user input command and we don't
  1536. X     * already have one */
  1537. X    if ((prompt_after_pager || builtin) && val == 0) {
  1538. X      MoveCursor(LINES,0);
  1539. X      StartBold();
  1540. X      Write_to_screen(" Command ('i' to return to index): ", 0);
  1541. X      EndBold();
  1542. X      fflush(stdout);
  1543. X      val = ReadCh();
  1544. X    }
  1545. X    
  1546. X    if (memory_lock) EndMemlock();    /* turn it off!! */
  1547. X
  1548. X    /* 'q' means quit current operation and pop back up to previous level -
  1549. X     * in this case it therefore means return to index screen.
  1550. X     */
  1551. X    return(val == 'i' || val == 'q' ? 0 : val);
  1552. X}
  1553. X
  1554. Xint
  1555. Xshow_line(buffer, builtin)
  1556. Xchar *buffer;
  1557. Xint  builtin;
  1558. X{
  1559. X    /** Hands the given line to the output pipe.  'builtin' is true if
  1560. X        we're using the builtin pager.
  1561. X        Return the character entered by the user to indicate
  1562. X        a command other than continuing with the display (only possible
  1563. X        with the builtin pager), otherwise 0. **/
  1564. X
  1565. X    if (builtin) {
  1566. X      strcat(buffer, "\n");
  1567. X      return(display_line(buffer));
  1568. X    }
  1569. X    errno = 0;
  1570. X    fprintf(pipe_wr_fp, "%s\n", buffer);
  1571. X    if (errno != 0)
  1572. X      dprint(1, (debugfile, "\terror %s hit!\n", error_name(errno)));
  1573. X    return(0);
  1574. X}
  1575. SHAR_EOF
  1576. chmod 0444 src/showmsg.c || echo "restore of src/showmsg.c fails"
  1577. echo "x - extracting src/showmsg_c.c (Text)"
  1578. sed 's/^X//' << 'SHAR_EOF' > src/showmsg_c.c &&
  1579. X
  1580. Xstatic char rcsid[] = "@(#)$Id: showmsg_c.c,v 2.20 89/03/25 21:47:21 syd Exp $";
  1581. X
  1582. X/*******************************************************************************
  1583. X *  The Elm Mail System  -  $Revision: 2.20 $   $State: Exp $
  1584. X *
  1585. X *             Copyright (c) 1986, 1987 Dave Taylor
  1586. X *             Copyright (c) 1988, 1989 USENET Community Trust
  1587. X *******************************************************************************
  1588. X * Bug reports, patches, comments, suggestions should be sent to:
  1589. X *
  1590. X *    Syd Weinstein, Elm Coordinator
  1591. X *    elm@dsinc.UUCP            dsinc!elm
  1592. X *
  1593. X *******************************************************************************
  1594. X * $Log:    showmsg_c.c,v $
  1595. X * Revision 2.20  89/03/25  21:47:21  syd
  1596. X * Initial 2.2 Release checkin
  1597. X * 
  1598. X *
  1599. X ******************************************************************************/
  1600. X
  1601. X/** This is an interface for the showmsg command line.  The possible
  1602. X    functions that could be invoked from the showmsg command line are
  1603. X    almost as numerous as those from the main command line and include
  1604. X    the following;
  1605. X
  1606. X       |    = pipe this message to command...
  1607. X       !    = call Unix command
  1608. X       <    = scan message for calendar info
  1609. X       b    = bounce (remail) message
  1610. X       d    = mark message for deletion
  1611. X       f    = forward message
  1612. X       g    = group reply
  1613. X       h    = redisplay this message from line #1, showing headers
  1614. X       <CR> = redisplay this message from line #1, weeding out headers
  1615. X       i,q  = move back to the index page (simply returns from function)
  1616. X       J    = move to body of next message
  1617. X       j,n  = move to body of next undeleted message
  1618. X       K    = move to body of previous message
  1619. X       k    = move to body of previous undeleted message
  1620. X       m    = mail a message out to someone
  1621. X       p    = print this (all tagged) message
  1622. X       r    = reply to this message
  1623. X       s    = save this message to a maibox/folder 
  1624. X       t    = tag this message
  1625. X       u    = undelete message
  1626. X       x    = Exit Elm NOW 
  1627. X
  1628. X    all commands not explicitly listed here are beeped at.  Use i)ndex
  1629. X    to get back to the main index page, please.
  1630. X
  1631. X    This function returns when it is ready to go back to the index
  1632. X    page.
  1633. X**/
  1634. X
  1635. X#include "headers.h"
  1636. X
  1637. Xint    screen_mangled = 0;
  1638. Xchar    msg_line[SLEN];
  1639. X#define store_msg(a)    (void)strcpy(msg_line,a)
  1640. X#define put_prompt()    PutLine0(LINES-3, 0, "Command:")
  1641. X#define put_help()    PutLine0(LINES-3, 45, "(Use 'i' to return to index.)")
  1642. X#define POST_PROMPT_COL    strlen("Command: ")
  1643. X
  1644. X
  1645. Xint
  1646. Xprocess_showmsg_cmd(command)
  1647. Xint command;
  1648. X{
  1649. X    int     i, intbuf;        /* for dummy parameters...etc */
  1650. X    int     ch;            /* for arrow keys */
  1651. X    int    key_offset;        /* for arrow keys */
  1652. X    int    istagged;        /* for tagging and subsequent msg */
  1653. X
  1654. X    Raw(ON);
  1655. X
  1656. X    while (TRUE) {
  1657. X      clear_error();
  1658. X      switch (command) {
  1659. X        case '?' : if (help(TRUE)) {
  1660. X             ClearScreen();
  1661. X             build_bottom();
  1662. X               } else screen_mangled = TRUE;
  1663. X               break;
  1664. X
  1665. X        case '|' : put_cmd_name("Pipe", TRUE);
  1666. X               (void) do_pipe();     /* do pipe - ignore return val */
  1667. X               ClearScreen();
  1668. X               build_bottom();
  1669. X               break; 
  1670. X
  1671. X        case '!' : put_cmd_name("System call", TRUE);
  1672. X               (void) subshell();         /* do shell regardless */
  1673. X               ClearScreen();
  1674. X               build_bottom();
  1675. X               break;
  1676. X
  1677. X        case '<' : 
  1678. X#ifdef ENABLE_CALENDAR
  1679. X               put_cmd_name("Scan messages for calendar entries", TRUE);
  1680. X               scan_calendar();
  1681. SHAR_EOF
  1682. echo "End of part 20"
  1683. echo "File src/showmsg_c.c is continued in part 21"
  1684. echo "21" > s2_seq_.tmp
  1685. exit 0
  1686.  
  1687.